home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 18.6 KB | 604 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSlcing.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWSLCING_H
- #include "FWSlcing.h"
- #endif
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OD Utils -----
-
- #ifndef _EDITRSET_
- #include "EditrSet.h"
- #endif
-
- #ifndef _BNDNSUTL_
- #include "BndNSUtl.h"
- #endif
-
- // ----- Foundation -----
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include "WinStat.xh"
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__STANDARDFILE__)
- #include <StandardFile.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding2
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CEmbeddingSelection, FW_CSelection)
-
- //========================================================================================
- // class FW_CEmbeddingSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::FW_CEmbeddingSelection
- //----------------------------------------------------------------------------------------
-
- FW_CEmbeddingSelection::FW_CEmbeddingSelection(Environment* ev,
- FW_Boolean allowPublish,
- FW_Boolean allowSubscribe) :
- FW_CSelection(ev, allowPublish, allowSubscribe)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::~FW_CEmbeddingSelection
- //----------------------------------------------------------------------------------------
-
- FW_CEmbeddingSelection::~FW_CEmbeddingSelection()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::IsSelectionOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* FW_CEmbeddingSelection::IsSelectionOnlyOneProxy(Environment* ev) const
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivPostInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingSelection::PrivPostInternalizeSelection(Environment* ev,
- FW_CCloneInfo* cloneInfo,
- FW_EInternalizeResult result)
- {
- switch (result)
- {
- case FW_kInternalizeFailed:
- FW_DEBUG_MESSAGE("PrivPostInternalizeSelection should not have been called");
- break;
-
- case FW_kInternalizeContent:
- PrivPostInternalizeContent(ev, cloneInfo);
- break;
-
- case FW_kInternalizePart:
- PrivPostInternalizePart(ev, cloneInfo);
- break;
-
- case FW_kInternalizeFrame:
- PrivPostInternalizeFrame(ev, cloneInfo);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivPostInternalizeContent
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingSelection::PrivPostInternalizeContent(Environment* ev, FW_CCloneInfo* cloneInfo)
- {
- if (cloneInfo->fClonedProxyList == NULL) // No embedded frames have been read
- return;
-
- FW_COrderedCollectionIterator ite(cloneInfo->fClonedProxyList);
- for (FW_MProxy* proxy = (FW_MProxy*)ite.First(); ite.IsNotComplete(); proxy = (FW_MProxy*)ite.Next())
- {
- proxy->PrivPostClone(ev, cloneInfo->GetScopeFrame(ev));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivPostInternalizePart
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingSelection::PrivPostInternalizePart(Environment* ev, FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- FW_ASSERT(cloneInfo->fClonedFrameID == kODNULLID);
-
- ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
- FW_CAcquiredODPart aqEmbeddedPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
-
- FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(embeddingScopeFrame);
-
- embeddingScopeFrame->EmbedSingleFrame(ev,
- aqEmbeddedPart,
- NULL,
- cloneInfo->fFrameShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivPostInternalizeFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingSelection::PrivPostInternalizeFrame(Environment* ev, FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
-
- FW_CEmbeddingFrame* scopeEmbeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(scopeEmbeddingFrame);
-
- // ----- Get the part -----
- ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
- FW_CAcquiredODPart aqNewPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
- FW_ASSERT(aqNewPart != NULL);
-
- FW_TRY
- {
- FW_CAcquiredODFrame aqNewFrame = myDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
- FW_ASSERT(aqNewFrame != NULL);
-
- aqNewFrame->SetContainingFrame(ev, scopeEmbeddingFrame->GetODFrame(ev));
-
- FW_CAcquiredODShape aqFrameShape = aqNewFrame->AcquireFrameShape(ev, NULL);
-
- scopeEmbeddingFrame->EmbedSingleFrame(ev,
- aqNewPart,
- aqNewFrame,
- aqFrameShape);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivHandleExternalizeSelection
- //----------------------------------------------------------------------------------------
- // Here we have two cases:
- // 1) The selection consist of only one embedded part. In this case
- // we just want to clone it into the clipboard
- // 2) The selection is two or more embedded parts or one or more
- // embedded parts plus content. In this case we externalize the selection
-
- void FW_CEmbeddingSelection::PrivHandleExternalizeSelection(Environment* ev,
- FW_EStorageKinds storageKind,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_ASSERT(cloneInfo->GetScopeFrame(ev));
-
- FW_MProxy *selectedProxy = IsSelectionOnlyOneProxy(ev);
- if (selectedProxy) // if the selection is only one embedded frame clone it into the clipboard
- {
- FW_CEmbeddingFrame* embeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
- FW_ASSERT(embeddingFrame);
-
- ODFrame* odEmbeddedFrame = selectedProxy->GetEmbeddedFrame(ev, embeddingFrame);
- FW_ASSERT(odEmbeddedFrame);
-
- DoExternalizeSingleEmbeddedFrame(ev, odEmbeddedFrame, destinationSU, cloneInfo);
-
- }
- else
- {
- // ----- First write out our embedded frames -----
- FW_CSelection::PrivHandleExternalizeSelection(ev, storageKind, destinationSU, cloneInfo);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::DoExternalizeSingleEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingSelection::DoExternalizeSingleEmbeddedFrame(Environment* ev,
- ODFrame* odEmbeddedFrame,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- destinationSU->AddProperty(ev, kODPropContentFrame);
- destinationSU->AddValue(ev, kODWeakStorageUnitRef);
-
- // Clone the embedded part into the root storage unit.
- FW_CAcquiredODPart aqPart = odEmbeddedFrame->AcquirePart(ev);
- ODID toRootID = cloneInfo->Clone(ev, aqPart->GetID(ev), destinationSU->GetID(ev), odEmbeddedFrame->GetID(ev));
-
- // Clone the embedded Frame to any storage unit. Must be done
- // after cloning the part because strongly reference the part
- ODID toFrameID = cloneInfo->Clone(ev, odEmbeddedFrame->GetID(ev), 0, odEmbeddedFrame->GetID(ev));
-
- // Weakly reference the frame
- destinationSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
-
- ODStorageUnitRef aSURef;
- destinationSU->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
-
- FW_CByteArray byteArray(&aSURef, sizeof(ODStorageUnitRef));
- destinationSU->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivHandleInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingSelection::PrivHandleInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- // ----- Test first if the was copy/cut of a single embedded frame
- if (sourceSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- {
- result = DoInternalizeSingleEmbeddedFrame(ev, sourceSU, cloneInfo);
- }
- else
- {
- // ----- Try to incorporate -----
- result = FW_CSelection::PrivHandleInternalizeSelection(ev, sourceSU, cloneInfo);
-
- // ----- Then try embedding -----
- if (result == FW_kInternalizeFailed)
- {
- // ----- Clone the part -----
- cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
- result = FW_kInternalizePart;
-
- // ----- Look for the frame shape -----
- cloneInfo->fFrameShape = PrivReadFrameShape(ev, sourceSU);
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::PrivReadFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CEmbeddingSelection::PrivReadFrameShape(Environment* ev, ODStorageUnit* sourceSU)
- {
- // ----- Look for a frame shape property -----
- ODShape* frameShape = NULL;
-
- if (sourceSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
- {
- // ----- Note: we focus on the property, ReadShape will focus on the value
- sourceSU->Focus(ev, kODPropFrameShape,
- kODPosUndefined,
- (ODValueType)NULL,
- (ODValueIndex)1,
- kODPosUndefined);
-
- frameShape = ::FW_NewODShape(ev);
- frameShape = frameShape->ReadShape(ev, sourceSU);
- }
-
- return frameShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::DoInternalizeSingleEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CEmbeddingSelection::DoInternalizeSingleEmbeddedFrame(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
-
- cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
- FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
-
- result = FW_kInternalizePart;
-
- // ----- Try Cloning the frame -----
- ODStorageUnitRef aSURef;
- sourceSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
-
- FW_CByteArray byteArray;
- sourceSU->GetValue(ev, sizeof(aSURef), byteArray);
- byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
-
- if (sourceSU->IsValidStorageUnitRef(ev, aSURef))
- {
- ODID sourceFrameID = sourceSU->GetIDFromStorageUnitRef(ev, aSURef);
- cloneInfo->fClonedFrameID = cloneInfo->Clone(ev, sourceFrameID, 0, 0);
- FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
-
- result = FW_kInternalizeFrame;
- }
-
- return result;
- }
-
- /*
- //----------------------------------------------------------------------------------------
- // CreateFileContainer
- //----------------------------------------------------------------------------------------
-
- ODContainer* CreateFileContainer(Environment* ev, ODSession* session, FSSpec* fsSpec)
- {
- ODByteArray* ba = CreateByteArray(fsSpec, sizeof(FSSpec));
- ODContainer* newContainer = session->GetStorageSystem(ev)->CreateContainer(ev, kODDefaultFileContainer, ba);
- DisposeByteArray(ba);
-
- return newContainer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::InsertNewPart
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CEmbeddingSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_Boolean result = FALSE;
- ODStorageUnit* partSU = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev);
- ODSession* session = partSU->GetSession(ev);
- ODWindowState* windowState = session->GetWindowState(ev);
- ODContainer* insertContainer = NULL;
- ODDocument* insertDocument = NULL;
-
- ODType partkind = NULL;
-
- // ----- StdGetFile please select an editor for the root part
- StandardFileReply sfReply;
- SFTypeList sfTypes;
-
- windowState->DeactivateFrontWindows(ev);
- StandardGetFile((FileFilterUPP)NULL,-1,sfTypes,&sfReply);
- windowState->ActivateFrontWindows(ev);
-
- // If the user selected a file and clicked 'OK'
- if (sfReply.sfGood)
- {
- insertContainer = CreateFileContainer(ev, session, &(sfReply.sfFile));
-
- // If the user chose an OpenDoc ODContainer
- if (insertContainer != NULL)
- {
- insertDocument = insertContainer->GetDocument(ev, kODDefaultDocument);
- ODDraft* nextDraft = NULL;
- ODDraft* insertDraft = insertDocument->GetBaseDraft(ev, kDPReadOnly);
-
- // New method for iterating over drafts in document without relying on failure
- if (insertDocument->Exists(ev, 0, insertDraft, kODPosLastAbove))
- do
- {
- insertDraft = insertDocument->GetDraft(ev, kDPReadOnly, NULL, insertDraft, kODPosLastAbove, TRUE);
- } while (insertDocument->Exists(ev, 0, insertDraft, kODPosLastAbove));
-
- ODStorageUnit* draftSU = insertDraft->GetDraftProperties(ev);
- ODStorageUnitRef suRef;
- draftSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
- draftSU->GetValue(ev, sizeof(ODStorageUnitRef), &suRef);
- ODStorageUnit* insertSU = insertDraft->GetStorageUnit(ev, draftSU->GetIDFromStorageUnitRef(ev, suRef));
-
- // ----- Clone the root part from the insertDraft to this Draft. As per Insert recipe.
- ODID scopeFrameID = scopeFrame->GetODFrame(ev)->GetStorageUnit(ev)->GetID(ev);
- ODDraft* destinationDraft = partSU->GetDraft(ev);
- ODDraftKey key = insertDraft->BeginClone(ev, destinationDraft, kODClonePaste);
-
- FW_TRY
- {
- insertSU->CloneInto(ev, key, partSU, scopeFrameID);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- // If an exception was raised while cloning, abort the insert
- insertDraft->AbortClone(ev, key);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- insertDraft->EndClone(ev, key);
-
- ODPart* newPart = partSU->GetDraft(ev)->GetPart(ev, insertSU->GetID(ev));
-
- // ----- Get the frame shape if any
- ODShape* frameShape = NULL;
- FW_VOLATILE(frameShape);
-
- FW_TRY
- {
- if (insertSU->Exists(ev, kODPropFrameShape, NULL, 0))
- {
- frameShape = ::FW_NewODShape(ev);
- insertSU->Focus(ev, kODPropFrameShape, kODPosUndefined, NULL, 0, kODPosUndefined);
- frameShape->ReadShape(ev, insertSU);
- }
-
- result = EmbedPart(ev, newPart, frameShape);
-
- FW_ReleaseODObject(ev, frameShape);
- frameShape = NULL
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- FW_ReleaseODObject(frameShape);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- // ----- Release -----
- FW_ReleaseODObject(ev, newPart);
- FW_ReleaseODObject(ev, insertSU);
- FW_ReleaseODObject(ev, draftSU);
- FW_ReleaseODObject(ev, insertDraft);
- FW_ReleaseODObject(ev, insertDocument);
- FW_ReleaseODObject(ev, insertContainer);
-
- result = TRUE;
- }
-
- }
-
- return result;
- }
- */
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingSelection::InsertNewPart
- //----------------------------------------------------------------------------------------
- // This is the wrong way to do Insert but it's fine for now
-
- FW_Boolean FW_CEmbeddingSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_Boolean result = FALSE;
-
- #ifdef FW_BUILD_MAC
- ODPart* odEmbeddedPart;
- ODStorageUnit* su = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev);
-
-
- ODType partkind = NULL;
- FW_CDynamicString partString;
-
- // StdGetFile please select an editor for the root part
- StandardFileReply sfReply;
- SFTypeList sfTypes;
- sfTypes[0] = 'shlb';
- sfTypes[1] = 'shlb';
- sfTypes[2] = 'shlb';
- sfTypes[3] = 'shlb';
-
- ODWindowState* windowState = su->GetSession(ev)->GetWindowState(ev);
-
- windowState->DeactivateFrontWindows(ev);
- ::StandardGetFile((FileFilterUPP)NULL,1,sfTypes,&sfReply);
- windowState->ActivateFrontWindows(ev);
-
- if (sfReply.sfGood)
- {
- short saveResFile = ::CurResFile();
- short resRefNum = ::FSpOpenResFile(&(sfReply.sfFile),fsRdPerm);
- EditorSet* theEditorSet = ODGetEditorSetFromResFile(resRefNum);
- ::CloseResFile(resRefNum);
- ::UseResFile(saveResFile);
-
- if (theEditorSet)
- {
- EditorSetIterator* itr = theEditorSet->CreateIterator();
- ODEditor editor = itr->First();
- delete itr;
-
- odEmbeddedPart = su->GetDraft(ev)->CreatePart(ev, NULL, editor);
- FW_ASSERT(odEmbeddedPart);
-
- delete theEditorSet;
-
- odEmbeddedPart->Externalize(ev); // DR3 I don't know why
- ((FW_CEmbeddingFrame*)scopeFrame)->EmbedSingleFrame(ev,
- odEmbeddedPart,
- NULL,
- NULL);
-
- result = TRUE;
-
- odEmbeddedPart->Release(ev); // To balance CreatePart
- }
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows code goes here!
- #endif
-
- return result;
- }
-
-